package leetcode.秋招.小马智行;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/8/28 15:54
 * @description：
 */
public class Main3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] nums = new int[N];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        HashMap<Integer, int[]> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            min = Math.min(min, nums[i]);
            max = Math.max(max, nums[i]);
            map.put(i, new int[]{min, max});
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int[] nums1 = map.get(i);
            int num1 = nums[i];
            for (int j = i + 1; j < nums.length; j++) {
                int[] nums2 = map.get(j);
                int num2 = nums[j];
                if (num2 >= nums1[0] && num2 <= nums1[1]
                        && num1 >= nums2[0] && num1 <= nums2[1]) {
                    if (i > 0) {
                        int[] pre1 = map.get(i - 1);
                        if (nums1[0] != Math.min(num2, pre1[0]) || nums1[1] != Math.max(num2, pre1[1])) {
                            continue;
                        }
                    }
                    if (j > 0) {
                        int[] pre1 = map.get(j - 1);
                        if (nums2[0] != Math.min(num1, pre1[0]) || nums2[1] != Math.max(num1, pre1[1])) {
                            continue;
                        }
                    }
                    //System.out.println(i + 1 + " " + (j + 1));
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
